<?php
App::import('Vendor','PHPExcel',array('file' => 'excel/PHPExcel.php'));
App::import('Vendor','PHPExcelWriter',array('file' => 'excel/PHPExcel/Writer/Excel5.php'));
App::import('Vendor','PHPExcelWriter',array('file' => 'excel/PHPExcel/IOFactory.php'));
//set_time_limit(0);
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of excel
 *
 * @author younessmondir
 */
class ExcelComponent extends Object {
var $xls;
        var $objet;
	var $sheet;
	var $writer;
        var $XlsName;
	function excelHelper() {
            
        }

        function openXls($xlsName){
            $this->objet = PHPExcel_IOFactory::createReader('Excel5');
            $this->XlsName=$xlsName;
            $this->xls = $this->objet->load($xlsName);
            $this->sheet = $this->xls->getSheet(0);
            $this->writer = PHPExcel_IOFactory::createWriter($this->xls,'Excel5');
        }

        function ajoutMissionOldModel(){
            $this->sheet->setCellValue('A1', 'MaitrePylos');
            $this->saveXls();
        }
        function saveMission($cell,$donnee){
            $this->sheet->setCellValue($cell, $donnee);
        }
        function ajoutDonneeParColEtLigne($numCol,$numLigne,$valeur){
            $this->sheet->setCellValueByColumnAndRow($numCol,$numLigne, $valeur);
        }
	function afficheDonneeParColEtLigne($numCol,$numLigne){
            return $this->sheet->getCellByColumnAndRow($numCol,$numLigne)->getValue();
           // $objPHPExcel->getActiveSheet()->getCellByColumnAndRow(1, 8)->getValue();
        }
        function ACells($numLigne,$numCol){
            return $this->sheet->getCellByColumnAndRow($numCol-1,$numLigne)->getValue();
           // $objPHPExcel->getActiveSheet()->getCellByColumnAndRow(1, 8)->getValue();
        }
        function ajoutFormule($numCol,$numLigne,$formule){
            $this->sheet->setCellValueByColumnAndRow($numCol,$numLigne, $formule);
        }
        function afficheRslt($numCol,$numLigne){
            return $this->sheet->getCellByColumnAndRow($numCol,$numLigne)->getCalculatedValue();
        }
        function saveXls(){
            $this->writer->save($this->XlsName);
        }
        function saveAsXls($name){
            $this->writer->save('files/'.$name.'.xls');
        }
	function _rows() {
		$i=5;
		foreach ($this->data as $row) {
			$j=0;
			foreach ($row as $field => $value) {
				if(!in_array($field,$this->blacklist)) {
					$this->sheet->setCellValueByColumnAndRow($j++,$i, $value);
				}
			}
			$i++;
		}
	}
        function closeXls(){
            unset($this->writer);
            unset ($this->sheet);
            unset ($this->xls);
            unset ($this->objet);
        }
        
}

?>
